const express = require('express');
const { idRegMiddleWare, errorMiddleWare } = require('./util')
const app = express()
const apiRouter = require('./api')
// 判断delete 和 put方法是否有传递id的中间件
app.use(idRegMiddleWare)

app.get('/', async (req, res) => {
    res.send('Hello World!')
})
// api开头的接口
apiRouter(app)


app.listen(8000, () => {
    console.log('8000 端口收到请求了')
})
/**
 * 错误解决中间件，参数一定是这4个，少了就不是了
 */
app.use(errorMiddleWare)
// module.exports = app
// app.listen相当于以下写法
// const server = http.createServer(app);
// server.listen(8000)

